package day_2022_7_to_8.day48;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @author haomin
 * @date 2022/07/21 09:59
 **/
public class Day6_1_Num539_TimePoints {
    public static void main(String[] args) {
        // ["23:59","00:00"];
        List<String> list = new LinkedList<>();
        list.add("12:12");
        list.add("00:13");
        System.out.println(findMinDifference(list));
    }
    public static int findMinDifference(List<String> timePoints) {
        int[] data = new int[timePoints.size()];
        int index = 0;

        // 将"HH:MM" 将转化为分钟
        for (String time : timePoints) {
            int hour = Integer.valueOf(new String(time.substring(0,2)));
            int minute = Integer.valueOf(new String(time.substring(3,5)));
            data[index] = hour*60 + minute;
            index++;
        }
        Arrays.sort(data);
        int min = Integer.MAX_VALUE;
        for (int i = 1; i < data.length; i++) {
            min = Math.min(min, data[i] - data[i - 1]);
        }

        // 最小值也可能是首尾时间差,形如"00:00" "23:59"
        return Math.min(min,data[0]+1440-data[data.length-1]);
    }
}